<?php $url = new Url();?>
<div class="left">
    <?php $this->widget("AdminKetquaXoso")?> 
    <?php $this->widget("AdminKetquaTrongngay")?>  
</div>
<div class="right-main">
    <div class="righ-cont">
        <div class="right">
            <div class="title_style"> <span><b>Bảng kết quả Xổ Số Miền Bắc</b></span></div>
            <div class="tool clearfix">
                <form name="Timkiem" action="<?=$url->createUrl("ketqua/truyenthong") ?>" method="GET">
                    <table cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                            <tr>
                                <td class="text-left"><label>Từ ngày</label>
                                    <?php
                                        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                        'id'=>'begin',
                                        'name'=>'begin',
                                        'value'=>$begin,
                                        'options'=>array(
                                        'showAnim'=>'fold',
                                        'dateFormat'=>'dd/mm/yy',
                                        ),
                                        'htmlOptions'=>array(
                                        'readonly'=>'readonly',
                                        ),
                                        ));
                                    ?>
                                    <label>Đến ngày</label>
                                    <?php
                                        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                        'id'=>'end',
                                        'name'=>'end',
                                        'value'=>$end,
                                        'options'=>array(
                                        'showAnim'=>'fold',
                                        'dateFormat'=>'dd/mm/yy',
                                        ),
                                        'htmlOptions'=>array(
                                        'readonly'=>'readonly',
                                        ),
                                        ));
                                    ?>
                                    <input type="submit" value="Tìm kiếm">

                                </td>

                            </tr>
                        </tbody>
                    </table>
                </form>
                <table>
                    <tbody  cellspacing="0" cellpadding="0" border="0" width="100%"> <tr>
                            <td class="text-left"><label>Thêm mới theo ngày</label> </td>
                            <td>
                                <form name="AddForm" action="<?=$url->createUrl("ketqua/createTruyenthong") ?>">
                                    <?php
                                        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                        'id'=>'ngay_quay',
                                        'name'=>'ngay_quay',
                                        'value'=>$end,
                                        'options'=>array(
                                        'showAnim'=>'fold',
                                        'dateFormat'=>'dd-mm-yy',
                                        ),
                                        'htmlOptions'=>array(
                                        'readonly'=>'readonly',
                                        ),
                                        ));
                                    ?>
                                    <input type="submit" value="Thêm mới"/>   
                                </form>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="table clearfix">
                <table cellspacing="0" cellpadding="0" border="0" width="100%">
                    <tbody>
                        <tr class="bg_gray">
                            <td width="7%"><b>Số TT</b></td>
                            <td width="23%"><b>Ngày quay</b></td>
                            <td width="17%"><b>Người nhập</b></td>
                            <td width="16%"><b>Xem</b></td>
                            <td width="18%"><b>Sửa</b></td>
                            <td width="19%"><b>Xóa</b></td>
                        </tr>
                        <?php for($i=0;$i<count($rows);$i++){?>
                            <tr id="delete<?=$i ?>">
                                <td><?= ($page-1)*10 +$i+1; ?></td>
                                <td><?=$rows[$i]["ngay_quay"] ?></td>
                                <td><?=$rows[$i]["modify_user"] !="" ? $rows[$i]["modify_user"]: $rows[$i]["create_user"] ?></td>
                                <td class="bg_yellow"><a href="<?=$url->createUrl("ketqua/truyenthongDetail",array("id"=>$rows[$i]["id"])) ?>"><em>Chi tiết...</em></a></td>
                                <td class="bg_yellow"><a href="<?=$url->createUrl("ketqua/editTruyenthong",array("id"=>$rows[$i]["id"])) ?>" class="edit">Sửa</a></td>
                                <td class="bg_yellow"><a href="javascript:void(0)" onclick="deleteRow<?=$i ?>();" class="del">Xóa</a></td>
                            </tr>
                            <script type="text/javascript">
                                function deleteRow<?=$i ?>(){
                                    var id = <?=$rows[$i]["id"]?>;
                                    var divId = 'delete<?=$i ?>';
                                    var answer = confirm("Bạn có chắc muốn xóa k?");
                                    var strUrl = '<?=$url->createUrl("ketqua/deleteTruyenthong") ?>';
                                    if(answer){

                                        $.ajax({
                                            type: "POST",
                                            url: strUrl,
                                            data: {
                                                id:id,
                                            },
                                            success: function(msg){
                                                if(msg==1){
                                                    $("#"+divId).html("<td colspan='6'>Đã xóa thành công</td>");
                                                }else{
                                                    $("#"+divId).html("Co Loi");
                                                }
                                            },

                                        });
                                    }
                                }
                            </script>
                            <?php }?>
                    </tbody>
                </table>
            </div>
            <div class="fillters clearfix">
                <ul class="paging fr">
                    <?php
                        $path = $url->createUrl("ketqua/truyenthong").'?begin='.$begin.'&end='.$end.'&';
                        echo Paging::showPageNavigation($page,$row_count,$path);
                    ?>
                </ul>
            </div>
        </div>
    </div>
</div>